package com.sinosoft.dsp.component.bpm.viewbean;

import com.sinosoft.dsp.component.bpm.service.core.BpmSelectItemsService;
import com.sinosoft.dsp.system.utils.Const;

/**
 * BPM事件的对象
 * 
 * @author 潘巍（PeterPan）
 * @since 2011-8-25 下午02:38:13
 * 
 */
public class BpmEventObject {

	private org.jbpm.xsdobject.On on;

	public BpmEventObject() {

	}

	public BpmEventObject(org.jbpm.xsdobject.On on) {
		this.on = on;
	}

	public org.jbpm.xsdobject.On getOn() {
		if (this.on == null) {
			this.on = new org.jbpm.xsdobject.On();
		}
		return on;
	}

	private Object getEvent() {
		if (getOn().getEventListenerGroup().size() > 0) {
			return getOn().getEventListenerGroup().get(0);
		}
		return null;
	}

	public boolean isHasTimer() {
		if (getOn().getTimer() != null) {
			if (!Const.isEmpty(getOn().getTimer().getDuedate())
					|| !Const.isEmpty(getOn().getTimer().getRepeat())) {
				return true;
			}
		}
		return false;
	}

	// 事件类别
	public String getType() {
		Object ev = getEvent();
		if (ev != null) {
			if (ev instanceof org.jbpm.xsdobject.TransitionType.EventListener) {
				return BpmSelectItemsService.SELECT_ITEM_EVENT_DEFINE_TYPE_EVENTLISTENER;
			} else if (ev instanceof org.jbpm.xsdobject.TransitionType.Hql) {
				return BpmSelectItemsService.SELECT_ITEM_EVENT_DEFINE_TYPE_HQL;
			} else if (ev instanceof org.jbpm.xsdobject.TransitionType.Sql) {
				return BpmSelectItemsService.SELECT_ITEM_EVENT_DEFINE_TYPE_SQL;
			} else if (ev instanceof org.jbpm.xsdobject.TransitionType.Java) {
				return BpmSelectItemsService.SELECT_ITEM_EVENT_DEFINE_TYPE_JAVA;
			} else if (ev instanceof org.jbpm.xsdobject.TransitionType.Script) {
				return BpmSelectItemsService.SELECT_ITEM_EVENT_DEFINE_TYPE_SCRIPT;
			} else if (ev instanceof org.jbpm.xsdobject.TransitionType.Mail) {
				return BpmSelectItemsService.SELECT_ITEM_EVENT_DEFINE_TYPE_MAIL;
			}
		}
		return null;
	}

	// 事件触发类别
	public String getEventType() {
		return getOn().getEvent();
	}

	// 执行方式
	public String getContinueType() {
		return getOn().getContinue().value();
	}

}
